public class Task07 {
    public static void main(String[] args) {
        Date date1 = new Date(2022, 5, 14);
        Date date2 = new Date(2022, 5, 13);
        Date date3 = new Date(2022, 5, 14);
        date1.print1();
        date2.print2();
        int compare=date1.compare(date2);
        if (compare==1) {
            System.out.println("date1大于date2");
        } else if (compare == -1) {
            System.out.println("date1小于date2");
        } else {
            System.out.println("date1等于date2");
        }
        compare=date1.compare(date3);
        if (compare==1) {
            System.out.println("date1大于date3");
        } else if (compare == -1) {
            System.out.println("date1小于date3");
        } else {
            System.out.println("date1等于date3");
        }
        compare=date2.compare(date3);
        if (compare==1) {
            System.out.println("date2大于date3");
        } else if (compare == -1) {
            System.out.println("date2小于date3");
        } else {
            System.out.println("date2等于date3");
        }
    }
}

class Date {
    int year;
    int month;
    int day;
    static int[] arr=new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
    Date(int year,int month,int day){
        if (month < 1 || month > 12) {
            throw new IllegalArgumentException("输入月的范围是1~12");
        }
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            if (month == 2) {
                arr[2]++;
            }
            if (arr[month] < day && day >= 0) {
                throw new IllegalArgumentException("输入正确的日期");
            }
            arr[2]--;
        } else {
            if (arr[month] < day && day >= 0) {
                throw new IllegalArgumentException("输入正确的日期");
            }
        }
        this.year=year;
        this.month=month;
        this.day=day;
    }

    void print1() {
        System.out.println(year+"-"+month+"-"+day);
    }

    void print2() {
        System.out.println(year+"/"+month+"/"+day);
    }

    int compare(Date  date) {
        if (year > date.year) {
            return 1;
        } else if (year<date.year) {
            return -1;
        }
        if (month >date.month) {
            return 1;
        } else if (month<date.month) {
            return -1;
        }
        if (day > date.day) {
            return 1;
        } else if (day<date.day) {
            return -1;
        }
        return 0;
    }
}